# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=blinksocks
pkgver=3.3.8
pkgrel=3
pkgdesc='A framework for building composable proxy protocol stack.'
arch=('any')
url='https://github.com/blinksocks/blinksocks'
license=('Apache')
depends=('nodejs' 'semver')
makedepends=('npm')
source=(https://registry.npmjs.org/$pkgname/-/$pkgname-$pkgver.tgz
        blinksocks@.service)
noextract=($pkgname-$pkgver.tgz)
sha512sums=('21573253717cca4d997e620754919def8562910c66987fccb112d1f2d72158ceff7857082fcb093df5bf5389973077673f3dbd3c28caea23feb4f9f841918e89'
            '709153bb95492cf0d6fa070ad8eef16220a97896731f688ec79e03cfddf112b4475fff589490740a8dae33b7bc4c1a331a4baf0d190eaf219f193fbb8128abeb')

package() {
  npm install -g --user root --prefix "$pkgdir"/usr "$srcdir"/$pkgname-$pkgver.tgz

  # Why 777? :/
  chmod -R u=rwX,go=rX "$pkgdir"
  # npm gives ownership of ALL FILES to build user
  # https://bugs.archlinux.org/task/63396
  chown -R root:root "${pkgdir}"

  rm -r "$pkgdir"/usr/lib/node_modules/blinksocks/node_modules/{,.bin/}semver

  install -Dm644 "$srcdir/blinksocks@.service" "$pkgdir/usr/lib/systemd/system/blinksocks@.service"
}
